package com.more.datasource.service;

import com.more.datasource.entity.User;
import com.more.datasource.mapper.test.UserMapper;
import com.more.datasource.mapper.test2.UserMapper2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserMapper2 userMapper2;

    /**
     * 两个数据库的回滚测试
     * @return
     */
    @Transactional
    public int insert() {
        User user=new User("nihao",15);
        userMapper.insert(user);
        userMapper2.insert(user);
        int a=1/0;
        return 1;
    }

    public User selectById(int id){
        return userMapper.selectById(id);
    }
}
